<?php

namespace App\Library;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Database\Eloquent\Model;

class ClLib
{
    private static string $APPID = 'COViGAey';

    private static string $APPKey = 'pzZq4QFS';

    /**
     * bank
     * @param string $realName
     * @param string $identity
     * @return array
     * @throws GuzzleException
     */
    public static function bank(string $realName, string $identity): array
    {
        $client = new Client;
        $response = $client->post('https://api.253.com/open/bankcard/card-two-auth', [
            'verify' => false,
            'form_params' => [
                'appId' => self::$APPID,
                'appKey' => self::$APPKey,
                'name' => $realName,//姓名
                'cardNo' => $identity,//银行卡号，限单个
            ],
        ]);
        $result = json_decode($response->getBody()->getContents(), true);
        payLog($result);
        return $result;
    }

    /**
     * mobileAddress
     * @param string $mobile
     * @return array
     * @throws GuzzleException
     */
    public static function mobileAddress(string $mobile): array
    {
        $client = new Client;
        $response = $client->post('https://api.253.com/open/unn/teladress', [
            'verify' => false,
            'form_params' => [
                'appId' => self::$APPID,
                'appKey' => self::$APPKey,
                'mobile' => $mobile,//手机号
                'orderNo' => serialNumber(),
            ],
        ]);
        $result = json_decode($response->getBody()->getContents(), true);
        payLog($result);
        return $result;
    }

    private static function test(): array
    {
        return [
            'chargeStatus' => 1,
            'message' => '成功',
            'data' => [
                'orderNo' => random(18, 1),
                'handleTime' => now()->toDateTimeString(),
                'result' => '01',
                'remark' => '认证一致',
                'bankName' => '中国工商银行',
                'cardType' => 'E时代卡',
                'cardCategory' => '借记卡',
            ],
        ];
    }
}
/*
 * {
    "tradeNo": "1214176777707741184",
    "chargeStatus": 1,
    "message": "成功",
    "data": {
        "orderNo": "20231019112320375509",
        "handleTime": "2024-03-04 11:45:02",
        "province": "上海",
        "city": "上海",
        "provinceCode": "021",
        "cityCode": "310100",
        "isp": "联通",
        "mobile": "15692131937",
        "postCode": "200000"
    },
    "code": "200000"
}
 */
